package com.ganee.agora.adapter

import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ganee.agora.R
import com.ganee.agora.manager.RecyclerViewHolder
import com.ganee.agora.model.HomeListBean
/**
 *    @author : EricCui
 *    date   : 2020-01-01 17:52
 *    desc   :
 */

class HomeBottomAdapter (entityList: MutableList<HomeListBean.DataAryBean>) : BaseQuickAdapter<HomeListBean.DataAryBean,
        RecyclerViewHolder>(R.layout.item_recyclerview_home_bottom,entityList){


    override fun convert(helper: RecyclerViewHolder, item: HomeListBean.DataAryBean?) {
        if (item != null){
            val icon = helper.getView<ImageView>(R.id.item_bottom_iv_pic) as ImageView
            Glide.with(mContext)
                    .load(item.activePic)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.drawable.home_placeholder)
                    .error(R.drawable.home_placeholder)
                    .into(icon)

            helper.setText(R.id.item_bottom_tv_title,item.eventTitle)
            if (null != item.location && !TextUtils.isEmpty(item.location)){
                helper.setText(R.id.item_bottom_tv_distance,"")
            }

            val tvPrice = helper.getView<TextView>(R.id.item_bottom_tv_price) as TextView
            if (null != item.activeType && "00" == item.activeType){
                tvPrice.text = "Free"
                tvPrice.visibility = View.VISIBLE
            } else if (null != item.activeType && "99" == item.activeType){
                if (null != item.amount){
                    tvPrice.text = "${item.amount}"
                } else {
                    tvPrice.text = "Free"
                }
                tvPrice.visibility = View.VISIBLE
            } else {
                tvPrice.visibility = View.GONE
            }
        }
    }

}